package cn.bitkit.mybatis.criteria;

import cn.bitkit.base.constants.DialectType;
import cn.bitkit.mybatis.DialectContext;
import cn.bitkit.mybatis.annotation.Query;
import cn.bitkit.mybatis.base.BaseCriteria;

/**
 * @author changbo
 */
public class LikeCriteria implements BaseCriteria {

    @Override
    public String getSql(Query query, String fieldName, Object fieldValue, String column) {
        String value;
        if(DialectContext.getDialectType() == DialectType.mysql) {
            value = "CONCAT('%', #{"+fieldName+"}, '%')";
        }else{
            value = "'%'||#{"+fieldName+"}||'%'";
        }
        return column + " like " + value;
    }

}
